import {
  applicationType,
  SubmitApplicationParams,
  organizerType,
} from "@/types/api/coutest";
import request from "../utils/request";
import { ResDataType } from "@/types/coutest";
import { PublishRaceParamsType } from "@/types/publishContest";
import { responseResult } from "@/types/api";
import { GetActivityRes } from "@/types/events";
/**
 * 查询竞赛列表
 * @param {string} page 当前页码
 * @param {string} limit 每页显示条数
 * @param {string} categoryId 分类id
 * @returns
 */
export function getContestList(
  page: string,
  limit: string,
  categoryId?: string
) {
  let url = `/api/contest/contest-list/${page}/${limit}`;
  categoryId !== undefined ? (url += "/?categoryId=" + categoryId) : "";
  return request.get<ResDataType<any>>(url);
}

/**
 * 当前最新竞赛前10条
 * @returns
 */
export function getNowCoutest() {
  return request.get<ResDataType<any>>(`/api/contest/contest-newByOrder`);
}

/**
 * 发布竞赛
 * @param {object} params ContestDto
 * @param {string} params.categoryId
 * @param {string} params.content
 * @param {string} params.cover
 * @param {string} params.description
 * @param {object} params.endDate
 * @param {object} params.enrollEndDate
 * @param {object} params.enrollStartDate
 * @param {array} params.imgNameList
 * @param {array} params.imgUrlList
 * @param {string} params.isComment
 * @param {string} params.isEmail
 * @param {number} params.isSystem
 * @param {string} params.isTeam
 * @param {string} params.isToll
 * @param {string} params.local
 * @param {string} params.organizer
 * @param {string} params.password
 * @param {number} params.personNum
 * @param {string} params.pushId
 * @param {object} params.startDate
 * @param {number} params.teamNum
 * @param {array} params.templateValueList
 * @param {string} params.title
 * @param {object} params.toll
 * @returns
 */
export function pushContest(params: PublishRaceParamsType) {
  return request.post(`/api/contest/push/contest`, params);
}

/**
 * 查询竞赛详情
 * @param {string} contestId 竞赛Id
 * @param {string} categoryId 类型Id
 * @returns
 */
export function getContestDetailsAPI(contestId: string, categoryId: string) {
  return request.get(`/api/contest/getContestInfo/${contestId}/${categoryId}`);
}

/**
 * 根据名称查询分类
 * @param {string} name 参数:分类名称
 * @returns
 */
export function findCategoryChildListByName(name: string) {
  return request.get(`/api/category/findCategoryChildListByName/${name}`);
}

/**
 * 点击立即报名 活动、竞赛等接口
 * @param {string} detailId 详情id
 * @param {string} type 类型
 * @returns
 */
export function applicationAPI(detailId: number, type: number) {
  return request.get<responseResult<applicationType>>(
    `/api/apply/user-template-application/${detailId}/${type}`
  );
}

/**
 * 点击确认报名,保存报名、竞赛触发的接口
 * @param {string} params.activityId
 * @param {number} params.applyStatus
 * @param {object} params.enrollTime
 * @param {number} params.isUse
 * @param {string} params.singleNo
 * @param {array} params.templateValueList
 * @param {string} params.type
 * @param {string} params.userId
 * @returns
 */
export function submitApplicationAPI(params: SubmitApplicationParams) {
  return request.post(`/api/apply/user-submit-application`, params);
}
/**
 * 获取发布竞赛
 * @returns
 */
export function getPublishContest() {
  return request.get<GetActivityRes>(`/api/u-center/message/publish/contest`);
}
/**
 * 获取主办方list
 * @returns
 */
export function getOrganizersList() {
  return request.get<organizerType>(`/api/organizers/organizers/getList`);
}

export function getCategoryList(name: string) {
  return request.get<ResDataType<any>>(
    `/api/category/findCategoryChildListByName/${name}`
  );
}

export function getDataByStatusOrType(status: string, type: string) {
  return request.get<ResDataType<any>>(
    `/api/u-center/message/activity/${type}/${status}`
  );
}

